<template>
	<div class="zhengtuojianhuo">
		<van-nav-bar :fixed="true" class="navBar" title="拼托拣货" left-arrow @click-left="$router.go(-1)"></van-nav-bar>

			<div class="goodsFromTwo" >

				<van-row class="goodsName">
					<div class="goodsRow">
						<div class="goodsOne">
							<span class="xian"></span> <span class="goodsLanel" style="width: 120px;" >拣货任务号：</span> {{editForm.bill}}
						</div>
					</div>
				</van-row>





				<!-- <van-row class="goodsName">
					<div class="goodsRow">
						<div class="goodsOne">
							<span class="xian"></span> <span class="goodsLanel" style="width: 120px;"  >仓位：</span> {{editForm.cwno}}
						</div>
					</div>
				</van-row> -->

				<van-row class="goodsName">
					<div class="goodsRow">
						<div class="goodsOne">
							<span class="xian"></span> <span class="goodsLanel" style="width: 120px;"  >顺序号：</span> {{editForm.route_c }}
						</div>
					</div>
				</van-row>

			</div>


		<div class="goodsFromWarp">

        <div class="goodsInputWarp">
          <div class="goodsInputLabel">
            <div class="goodsInputBorder"></div>
            <div class="skuName">位置：</div>
          </div>


          <div class="skuNoInput">
            {{editForm.hqp}}
          </div>


          <div class="searchBtn">
            <button :disabled="isdisabled"  @click.stop="_getAddressBtn()" >
              <van-icon name="ellipsis" color="#1989fa"  />
            </button>
          </div>
        </div>


        <div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">商品编码：</div>
						</div>

						<div class="skuNoInput">
							{{editForm.itemid}}
						</div>

						<div class="searchBtn">
              <button :disabled="isdisabled">
                <van-icon name="arrow-up" 	v-if="px =='Y'" @click="px = 'N'"	size="20" color="#1989fa"  />
								<van-icon name="arrow-down" v-if="px =='N'" @click="px = 'Y'" size="20" color="#1989fa" />
              </button>
						</div>

				</div>



				<div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">商品名称：</div>
						</div>
						<div class="skuNoInput">
							{{editForm.subsname}}
						</div>
				</div>

        <div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">商品条码：</div>
						</div>
						<div class="skuNoInput">
							{{editForm.barcode}}
						</div>
				</div>


        <div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">分配箱装：</div>
						</div>


						<div class="skuNoInput">
								{{editForm.unit}}
						</div>

						<div class="goodsInputLabel">
							<div class="skuName">箱数：</div>
						</div>

						<van-field
							 v-if="addmode"
							 class="skuInput"
							 v-model="editForm.pack"
							 placeholder="请输入箱数"
						 />

						<div class="skuNoInput" v-if="!addmode">
							{{editForm.pack}}
						</div>
				</div>







				<div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">总数量：</div>
						</div>
						<div class="skuNoInput">
							{{editForm.yjtotqty}}
						</div>


            <div class="goodsInputLabel">
							<div class="skuName">散数：</div>
						</div>

            <van-field
							 v-if="addmode"
							 class="skuInput"
							 v-model="editForm.qty"
							 placeholder="请输入散数"
						 />

						<div class="skuNoInput"  v-if="!addmode">
								{{editForm.qty}}
						</div>

				</div>

        <div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName">仓位：</div>
						</div>
						<div class="skuNoInput">
							{{editForm.cwno}}
						</div>

            <div class="huanshangpin" @click="isSkuVisible = true" v-if="skuData.length > 0 && editForm.bill >'' ">换商品</div>
				</div>



      <scan-input
        :item-id="editForm.itemid"
        :cwno="editForm.cwno"
        :operator-id="ryuser.operatorid"
        :kq-id="ryuser.kqid"
        @both-scanned="onBothScanned"
        ref="scanInput"
      />

      <!-- 目标容器输入框 -->
      <div class="goodsInputWarp">
        <div class="goodsInputLabel">
          <div class="goodsInputBorder"></div>
          <div class="skuName">目标容器：</div>
        </div>
        <van-field
          class="skuInput jhrqid-input"
          v-model="editForm.jhrqid"
          placeholder="请输入目标容器"
          ref="jhrqidInput"
          clearable
        />
      </div>
		</div>







		<div class="skuBtnThree">
			<van-button round type="info" :disabled="isdisabled" @click="lingquBtn()">领取任务</van-button>
			<van-button round type="info" :disabled="!canSubmitSave" @click="_saveSku()">拣货确认</van-button>
      <van-button round type="info" :disabled="isdisabled" @click="overBtn()">结束容器</van-button>
		</div>

		<div class="skuBtnThree">
      <van-button round type="info" style="width: 80px;"   v-if="!addmode" :disabled="isdisabled" @click="editSkuClick()">修改</van-button>
      <van-button round type="info" style="width: 80px;"   v-if="addmode" @click="saveSkuBtnClick()">确认修改</van-button>
		</div>



		<van-overlay :show="isLingQuVisible" :lock-scroll="false">
			<div class="shipandanWrapper">
					<van-sticky>
						<van-nav-bar class="navBar" title="仓位列表" left-arrow @click-left="isLingQuVisible = false"></van-nav-bar>
					</van-sticky>
					<div class="shipandanCon" @click.stop>
							<div  v-for="(row,i) in lingquData" :key="i" class="danjuRow"  @click="lingquClick(row)">
								<van-row class="skuList">
								  <van-col span="24"> <span>任务号：</span> {{row.bill}}</van-col>
								</van-row>

								<van-row class="skuList" >
								  <van-col span="24"> <span>仓位：</span> {{row.cwno}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>拼接仓位：</span> {{row.cwnop}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>顺序号：</span> {{row.route_c}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="12"> <span>集货位：</span> {{row.wno}}</van-col>
									<van-col span="12"> <span>仓库：</span> {{row.whsid}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="12"> <span>区：</span> {{row.q_no}}</van-col>
									<van-col span="12"> <span>排：</span> {{row.p_no}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="12"> <span>出货总量：</span> {{row.yjtotqty}}</van-col>
									<van-col span="12"> <span>托盘总量：</span> {{row.tqty}}</van-col>
								</van-row>

							</div>
					</div>
			</div>
		</van-overlay>


		<van-overlay :show="isSkuVisible" :lock-scroll="false">
			<div class="shipandanWrapper">
					<van-sticky>
						<van-nav-bar class="navBar" title="商品列表" left-arrow @click-left="isSkuVisible = false"></van-nav-bar>
					</van-sticky>
					<div class="shipandanCon" @click.stop>
							<div  v-for="(row,i) in skuData" :key="i" class="danjuRow" @click="selectSkuClick(row)" >
								<van-row class="skuList">
								  <van-col span="24"> <span>商品名称：</span> {{row.subsname}}</van-col>
								</van-row>

								<van-row class="skuList" >
								  <van-col span="24"> <span>条码：</span> {{row.barcode}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>商品编码：</span> {{row.itemid}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="12"> <span>箱装：</span> {{row.unit}}</van-col>
									<van-col span="12"> <span>箱数：</span> {{row.pack}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>总数量：</span> {{row.yjtotqty}}</van-col>
								</van-row>

                <van-row class="skuList"  >
									<van-col span="24"> <span>仓位：</span> {{row.cwno}}</van-col>
								</van-row>

							</div>
					</div>
			</div>
		</van-overlay>


    <!-- 地址弹窗 -->
		<van-overlay :show="isAddressVisible" :lock-scroll="false">
			<div class="shipandanWrapper">
					<van-sticky>
						<van-nav-bar class="navBar" title="位置列表" left-arrow @click-left="isAddressVisible = false"></van-nav-bar>
					</van-sticky>
					<div class="shipandanCon" @click.stop>
							<div  v-for="(row,i) in addressData" :key="i" class="danjuRow" @click="selectAddressClick(row,i)" >
								<van-row class="skuList" >
								  <van-col span="24"> <span>货区排：</span> {{row.hqp}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="12"> <span>区：</span> {{row.q_no}}</van-col>
									<van-col span="12"> <span>通道：</span> {{row.p_no}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="12"> <span>七层总数：</span> {{row.qczs}}</van-col>
									<van-col span="12"> <span>四层：</span> {{row.sczs}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>仓位自：</span> {{row.cwno_f}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>七层总数：</span> {{row.qczs}}</van-col>
								</van-row>

								<van-row class="skuList"  >
									<van-col span="24"> <span>四层总数：</span> {{row.sczs}}</van-col>
								</van-row>


							</div>
					</div>
			</div>
		</van-overlay>

	</div>
</template>

<script>
import ScanInput from '@/components/ScanInput.vue'

export default {
  name: 'pintuojianhuo',
  data() {
    return {
			editForm:{
				subsname:'',
        barcode:'',
				itemid:'',
				unit:'',
				pack:'',
				qty:'',
				jhrqid:'',
				storename:'', //门店名称
				bill:'', //拣货任务号
				cwno:'', //仓位
				cwnop:'', //拼接显示仓位
				route_c:'', //出货仓位的顺序号
				wno:'', //集货位
				q_no:'', //区
				p_no:'', //排
				yjtotqty:'', //出货总数量
				whsid:'', //仓库
				tqty:'', //托盘总数量
				renwuid:'', //任务号
				mbqx_hq	:'', //去向目的 01整件分播   02 拆零分播
        hqp:'',//位置
        cwno_f:'',//仓位自
        cwno_t:'',//仓位托
        lcjh_type:'',// 01 整件分播   02 拆零分播
        sczs:'',//四层总数
        jhrqxg:'',//拣货单号
			},
			isdisabled:false,
			lingquData:[
				{
					bill:'',
				}
			],
			isLingQuVisible:false,
			skuData:[
				{
					subsname:''
				}
			],
			isSkuVisible:false,
			addressData:[],
			isAddressVisible:false,
      ruleForm:{
        scanInput: '',
        itemid: '',
        cwno: '',
      },
			isItemScanned: false,
			isCwnoScanned: false,  // 添加仓位扫描状态
      addmode:false,
      canSubmitSave: false,  // 添加提交按钮状态控制
      verifyForm: {
        itemid: '',
        cwno: '',
        bill: ''
      },
      px:'Y',

		};
  },
	computed: {
	   ryuser: function(){
	     return this.GWO(true).gUSER;
	   }
	},
  methods: {
    saveSkuBtnClick(){
      console.log(this.editForm)
      var _self = this;
				var ldemodata = [{retval:0, errmsg:'返回数据集'},]
				this.MYPOST({
					'method':'dgate',
					'pname':'f_wmsa_jianhuo',
					'i':this.FNULLE([
            'opmode','PTJH_xgitem',
            'kqid', this.ryuser.kqid,
            'czyid',this.ryuser.operatorid,
            'jhrqxg',this.editForm.jhrqxg,
            'cwno',this.editForm.cwno,
            'yjtotqty',this.editForm.yjtotqty,
            'pack',this.editForm.pack,
            'qty',this.editForm.qty,
            'unit',this.editForm.unit,
            'itemid',this.editForm.itemid,
            'subid',this.editForm.subid,
            'whsid',this.editForm.whsid,
            'renwuid',this.editForm.renwuid,
            'ck_storeid',this.editForm.ck_storeid,
            'bill',this.editForm.bill,
					])
					},'修改商品详情',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
					if(ret_iserr){ //传入的true参数,理论上不会有此回调了
						_self.$toast.fail('查询失败')
						_self.$store.commit('hideLoading');
					}else{
						var rtn_json_obj = null;
						_self.$store.commit('hideLoading');
						if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
						}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
						}
            if(rtn_json_obj[0].ret_ret == '-1'){
              _self.$toast(rtn_json_obj[0].ret_mess)
            }else{
              _self.$toast(rtn_json_obj[0].ret_mess)
              _self.$toast.success('修改成功')
              _self.addmode = false
              _self.isdisabled = false
              _self.lingquBtn()  //重新领取任务
              if (_self.$refs.scanInput) {
								_self.$refs.scanInput.reset()
								_self.$nextTick(() => {
									_self.$refs.scanInput.focus()
								})
							}
            }
					}
				});
    },
    editSkuClick(){
			this.addmode = !this.addmode
		},
		_getSku(){
			if(this.editForm.cwno >''){

			}else{
				return this.$toast.fail('请先领取任务')
			}
			  var _self = this;
				var ldemodata = [{retval:0, errmsg:'返回数据集'},]
				this.MYPOST({
					'method':'dgate',
					'pname':'f_wmsa_jianhuo',
					'i':this.FNULLE([
					'opmode','PTJH_qryitem',
					'kqid', this.ryuser.kqid,
					'czyid',this.ryuser.operatorid,
					'whsid',this.editForm.whsid,
					'renwuid',this.editForm.renwuid,
					'cwno',this.editForm.cwno,
					'bill',this.editForm.bill,
					])
					},'获取商品详情',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
					if(ret_iserr){ //传入的true参数,理论上不会有此回调了
						_self.$toast.fail('查询失败')
						_self.$store.commit('hideLoading');
					}else{
						var rtn_json_obj = null;
						_self.$store.commit('hideLoading');
						if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
						}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
						}
						_self.lingquData = rtn_json_obj
						console.log("得到商品详情")
						console.log(rtn_json_obj)
						_self.skuData = rtn_json_obj
            if(_self.skuData.length >=1){
              _self.editForm.cwno     = _self.skuData[0].cwno
              _self.editForm.yjtotqty = _self.skuData[0].yjtotqty
              _self.editForm.pack     = _self.skuData[0].pack
              _self.editForm.qty      = _self.skuData[0].qty
              _self.editForm.unit     = _self.skuData[0].unit
              _self.editForm.itemid   = _self.skuData[0].itemid
              _self.editForm.subsname  = _self.skuData[0].subsname
              _self.editForm.subid    = _self.skuData[0].subid
              _self.editForm.barcode  = _self.skuData[0].barcode
              _self.$nextTick(() => {
                if (_self.$refs.scanInput) {
                  _self.$refs.scanInput.focus()
                } else {
                  console.log('scanInput输入框不存在')
                }
              })
            }else{
              _self.$toast.fail('暂无获取商品详情')
              _self.resetAll()
            }
					}
				});
		},
		lingquBtn(){
			var _self = this;
			var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			this.MYPOST({
				'method':'dgate',
				'pname':'f_wmsa_jianhuo',
				'i':this.FNULLE([
				'opmode','PTJH_lqbill',
          'czyid',this.ryuser.operatorid,
          'kqid', this.ryuser.kqid,
          'route_c',this.editForm.route_c,
          'q_no',this.editForm.q_no,
          'p_no',_self.editForm.p_no,
          'lcjh_type',_self.editForm.lcjh_type,
          'px',_self.px,
				])
				},'领取任务',false, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了

        // _self.$toast.fail()
          _self.$dialog.alert({
          message: ret_errmess,
          }).then(() => {
                _self.resetAll()
          });
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					_self.lingquData = rtn_json_obj
					console.log("得到领取任务")
					console.log(rtn_json_obj)

					if(_self.lingquData.length > 0){
						_self.editForm.route_c = _self.lingquData[0].route_c
						_self.editForm.whsid = 	_self.lingquData[0].whsid
						_self.editForm.tqty = 		_self.lingquData[0].tqty
						_self.editForm.bill 		= 		_self.lingquData[0].bill
						_self.editForm.renwuid 	= 		_self.lingquData[0].renwuid
						_self.editForm.cwno 		=		 _self.lingquData[0].cwno
						_self.editForm.storename 		=		 _self.lingquData[0].storename
            _self.editForm.jhrqxg   = _self.lingquData[0].jhrqxg
            _self.editForm.ck_storeid   = _self.lingquData[0].ck_storeid
            _self._getSku()
					}else{
            _self.resetAll()
            _self.$toast.fail('暂无领取任务')
					}
				}
			});
		},
		selectSkuClick(row){
			this.editForm.cwno = row.cwno
			this.editForm.yjtotqty = row.yjtotqty
			this.editForm.pack = row.pack
			this.editForm.qty = row.qty
			this.editForm.unit = row.unit
			this.editForm.itemid  = row.itemid
			this.editForm.subsname  = row.subsname
			this.editForm.subid  = row.subid
      this.editForm.barcode  = row.barcode
      this.editForm.jhrqxg   = row.jhrqxg
      this.editForm.ck_storeid   = row.ck_storeid
      this.editForm.whsid   = row.whsid
      this.editForm.renwuid   = row.renwuid
      this.editForm.bill   = row.bill
      this.editForm.cwno   = row.cwno
      this.editForm.storename   = row.storename
      this.editForm.lcjh_type   = row.lcjh_type
      this.editForm.sczs   = row.sczs
      this.editForm.cwno_f   = row.cwno_f
      this.editForm.cwno_t   = row.cwno_t
			this.isSkuVisible = false
      this.$refs.scanInput.reset()
      this.$nextTick(() => {
        this.$refs.scanInput.focus()
      })
      this.canSubmitSave = false
		},
		saveGoodsBtn(){
			let sendData = {
				'kqid':this.ryuser.kqid,
				'czyid':this.ryuser.operatorid,
				'bill':this.editForm.bill,
				'jhrqid':this.editForm.jhrqid,
				'cwno':this.editForm.cwno,
				'yjtotqty':this.editForm.yjtotqty,
				'pack':this.editForm.pack,
				'qty':this.editForm.qty,
				'unit':this.editForm.unit,
				'itemid':this.editForm.itemid,
				'subid':this.editForm.subid,
				'whsid':this.editForm.whsid,
				'renwuid':this.editForm.renwuid,
			}
			console.log(sendData)

				var _self = this;
				var ldemodata = [{retval:0, errmsg:'返回数据集'},]
				this.MYPOST({
						'method':'dgate',
						'pname':'f_wmsa_jianhuo',
						'i':this.FNULLE([
						'opmode','PTJH_qritem',
						'kqid', this.ryuser.kqid,
						'czyid',this.ryuser.operatorid,
						'bill',this.editForm.bill,
						'jhrqid', this.editForm.jhrqid,
						'cwno',this.editForm.cwno,
						'yjtotqty',this.editForm.yjtotqty,
						'pack',this.editForm.pack,
						'qty',this.editForm.qty,
						'unit',this.editForm.unit,
						'itemid',this.editForm.itemid,
						'subid',this.editForm.subid,
						'whsid',this.editForm.whsid,
						'renwuid',this.editForm.renwuid,
					])
					}, '确认拣货',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
					if(ret_iserr){ //传入的true参数,理论上不会有此回调了
						_self.$toast.fail('查询失败')
						_self.$store.commit('hideLoading');
					}else{
						var rtn_json_obj = null;
						_self.$store.commit('hideLoading');
						if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
						}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
						}
						// _self.skuData = rtn_json_obj
						console.log("得到确认拣货")
						console.log(rtn_json_obj[0])
						if(rtn_json_obj[0].ret_ret == '-1'){
							_self.$toast(rtn_json_obj[0].ret_mess)
						}else{
							_self.$toast(rtn_json_obj[0].ret_mess)
              _self.lingquBtn() //重新领取任务
							_self.editForm.jhrqid		= ''
							_self.editForm.cwno			= ''
							_self.editForm.yjtotqty	= ''
							_self.editForm.pack			= ''
							_self.editForm.qty			= ''
							_self.editForm.unit			= ''
							_self.editForm.itemid		= ''
							_self.editForm.subid		= ''
							_self.editForm.whsid		= ''
							_self.editForm.renwuid	= ''
							_self.editForm.storename= ''
							_self.editForm.subsname= ''
							_self.editForm.hqp		= ''
							_self.editForm.q_no		= ''
							_self.editForm.p_no		= ''
							_self.editForm.cwno_f	= ''
							_self.editForm.cwno_t	= ''
							_self.editForm.lcjh_type	= ''
							_self.editForm.sczs		= ''
              _self.resetScanStatus()
              // 保存成功后重置状态
              _self.canSubmitSave = false
              _self.$refs.scanInput.reset()
              // 重新聚焦到扫描输入框
              _self.$nextTick(() => {
                _self.$refs.scanInput && _self.$refs.scanInput.focus()
              })
						}
					}
				});
		},
		overBtn(){
			var _self = this;
			var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			this.MYPOST({
					'method':'dgate',
					'pname':'f_wmsa_jianhuo',
					'i':this.FNULLE([
					'opmode','PTJH_jsrq',
					'kqid', this.ryuser.kqid,
					'czyid',this.ryuser.operatorid,
					'jhrqid', this.editForm.jhrqid,
				])
				}, '确认拣货',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了
					_self.$toast.fail('查询失败')
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					// _self.skuData = rtn_json_obj
					console.log("得到确认拣货")
					console.log(rtn_json_obj[0])
					if(rtn_json_obj[0].ret_ret == '-1'){
						_self.$toast(rtn_json_obj[0].ret_mess)
            _self.resetAll()
					}else{
						_self.$toast(rtn_json_obj[0].ret_mess)
						_self.editForm.jhrqid	= ''
					}
				}
			});
		},
		_getAddressBtn(){
			var _self = this;
			var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			this.MYPOST({
				'method':'dgate',
				'pname':'f_wmsa_jianhuo',
				'i':this.FNULLE([
				'opmode','PTJH_qrywz',
				'czyid',this.ryuser.operatorid,
				'kqid', this.ryuser.kqid,
				])
				}, '获取位置',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了
					_self.$toast.fail('查询失败')
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					console.log(rtn_json_obj)
					_self.addressData = rtn_json_obj;
          if(_self.addressData.length > 0){
            _self.isAddressVisible = true;
          }else{
            _self.$toast.fail('暂无位置')
          }
				}
			});
		},
    // 选择地址
		selectAddressClick(row,i){
			this.editForm.hqp = row.hqp;
			this.editForm.q_no = row.q_no;
			this.editForm.p_no = row.p_no;
			this.editForm.cwno_f = row.cwno_f;
			this.editForm.cwno_t = row.cwno_t;
			this.isAddressVisible = false;
		},
    resetScanStatus() {
      this.ruleForm.itemid = ''
      this.ruleForm.cwno = ''
      this.isItemScanned = false
      this.isCwnoScanned = false
      if (this.$refs.scanInput) {
        this.$refs.scanInput.focus()
      }
    },

    onBothScanned() {
      console.log('两个都扫描成功')
      this.canSubmitSave = true
      // 使用setTimeout确保DOM更新完成
      setTimeout(() => {
        const input = document.querySelector('.jhrqid-input input')
        if (input) {
          console.log('找到目标输入框，设置焦点')
          input.focus()
        } else {
          console.log('未找到目标输入框')
        }
      }, 100)
    },

    _saveSku() {
      let sendData = {
        'kqid': this.ryuser.kqid,
        'czyid': this.ryuser.operatorid,
        'bill': this.editForm.bill,
        'jhrqid': this.editForm.jhrqid,
        'cwno': this.editForm.cwno,
        'yjtotqty': this.editForm.yjtotqty,
        'pack': this.editForm.pack,
        'qty': this.editForm.qty,
        'unit': this.editForm.unit,
        'itemid': this.editForm.itemid,
        'subid': this.editForm.subid,
        'whsid': this.editForm.whsid,
        'renwuid':this.editForm.renwuid,
      }
      console.log(sendData)
      var _self = this;
      var ldemodata = [{retval:0, errmsg:'返回数据集'},]
      this.MYPOST({
        'method': 'dgate',
        'pname': 'f_wmsa_jianhuo',
        'i': this.FNULLE([
          'opmode','PTJH_qritem',
          'kqid',this.ryuser.kqid,
          'czyid',this.ryuser.operatorid,
          'bill',this.editForm.bill,
          'jhrqid', this.editForm.jhrqid,
          'cwno',this.editForm.cwno,
          'yjtotqty',this.editForm.yjtotqty,
          'pack',this.editForm.pack,
          'qty',this.editForm.qty,
          'unit',this.editForm.unit,
          'itemid',this.editForm.itemid,
          'subid',this.editForm.subid,
          'whsid',this.editForm.whsid,
          'renwuid',this.editForm.renwuid,
        ])
      }, '确认拣货', true, ldemodata, function(ret_obj, ret_iserr, ret_errmess, ret_oldresp) {
        if(ret_iserr) {
          _self.$toast.fail('查询失败')
          _self.$store.commit('hideLoading');
        } else {
          var rtn_json_obj = null;
          _self.$store.commit('hideLoading');
          if(ret_obj != null) {
            rtn_json_obj = ret_obj;
          } else {
            rtn_json_obj = _self.arr2Obj(ret_oldresp.data);
          }
          console.log("得到确认拣货")
          console.log(rtn_json_obj[0])
          if(rtn_json_obj[0].ret_ret == '-1') {
            _self.$toast(rtn_json_obj[0].ret_mess)
            _self.resetScanStatus()
          } else {
            _self.$toast(rtn_json_obj[0].ret_mess)
            _self.lingquBtn() //重新领取任务
            _self.editForm.jhrqid = ''
            _self.editForm.cwno = ''
            _self.editForm.yjtotqty = ''
            _self.editForm.pack = ''
            _self.editForm.qty = ''
            _self.editForm.unit = ''
            _self.editForm.itemid = ''
            _self.editForm.subid = ''
            _self.editForm.whsid = ''
            _self.editForm.renwuid = ''
            _self.editForm.storename = ''
            _self.editForm.subsname = ''
            _self.editForm.hqp = ''
            _self.editForm.q_no = ''
            _self.editForm.p_no = ''
            _self.editForm.cwno_f = ''
            _self.editForm.cwno_t = ''
            _self.editForm.lcjh_type = ''
            _self.editForm.sczs = ''
            _self.editForm.barcode = ''
            _self.resetScanStatus()
          }
        }
      });

      // 保存成功后重置状态
      _self.canSubmitSave = false
      _self.$refs.scanInput.reset()
      // 重新聚焦到扫描输入框
      _self.$nextTick(() => {
        _self.$refs.scanInput && _self.$refs.scanInput.focus()
      })
    },
    resetAll(){
      var _self = this;
      _self.editForm = {
        bill:'',
        subsname:'',
        barcode:'',
        itemid:'',
        unit:'',
        pack:'',
        qty:'',
        jhrqid:'',
        storename:'', //门店名称
        bill:'', //拣货任务号
        cwno:'', //仓位
        cwnop:'', //拼接显示仓位
        route_c:'', //出货仓位的顺序号
        wno:'', //集货位
        q_no:'', //区
        p_no:'', //排
        yjtotqty:'', //出货总数量
        whsid:'', //仓库
        tqty:'', //托盘总数量
        renwuid:'', //任务号
        mbqx_hq	:'', //去向目的 01整件分播   02 拆零分播
        hqp:'',//位置
        cwno_f:'',//仓位自
        cwno_t:'',//仓位托
        lcjh_type:'',// 01 整件分播   02 拆零分播
        sczs:'',//四层总数
        jhrqxg:'',//拣货单号
      }
      _self.addressData = []
      _self.resetScanStatus()
      // 保存成功后重置状态
      _self.canSubmitSave = false
      _self.$refs.scanInput.reset()
      // 重新聚焦到扫描输入框
      _self.$nextTick(() => {
        _self.$refs.scanInput && _self.$refs.scanInput.focus()
      })
    }
  },
  mounted() {
    // 初始聚焦到扫描输入框
    this.$nextTick(() => {
      this.$refs.scanInput && this.$refs.scanInput.focus()
    })
  },
	components: {
    ScanInput
	},
};
</script>

<style lang="scss" scoped>
	// 引入公共样式
	@import '@/assets/css/base.scss';
	@import '@/assets/css/input.scss';
	div.zhengtuojianhuo{
		padding-top: 50px;
	}

  // 原有样式
div.zhuangcheWarp {
  // ... 原有样式 ...

  // 新增checkbox样式
  .van-checkbox {
    font-size: 16px;
    margin-left: 10px;

    /deep/ .van-checkbox__label {
      color: #666;
    }
  }
}

.simple-status {
  margin: 10px 0;
  padding: 0 15px;
  display: flex;
  gap: 20px;
  justify-content: center;

  span {
    display: flex;
    align-items: center;
    color: #666;
    font-size: 14px;

    &.success {
      color: #07c160;
    }
  }
}

.huanshangpin{
    width:100px;
    color: #1989fa;
}

// 新增验证提示样式
.validate-tip {
  font-size: 14px;
  padding: 5px 0;
  margin-top: 5px;

  &.success {
    color: #67C23A;
  }

  &.error {
    color: #F56C6C;
  }
}


.skuBtnThree{
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  box-sizing: border-box;
  padding: 0 15px;
}
</style>
